/**
 * 
 */
package com.py.credit.service.impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import com.py.credit.common.ServiceException;
import com.py.credit.dao.AuScontentDao;
import com.py.credit.entity.AuScontent;
import com.py.credit.service.AuScontentService;
import com.py.credit.service.RemoteBaseService;
import com.py.credit.utils.SQLBuilder;
import com.py.credit.utils.UuidUtil;
import com.py.framework.core.common.Page;

/**
 * @author dd
 *
 */
@Service
public class AuScontentServiceImpl implements AuScontentService {

	@Autowired
	private AuScontentDao auScontentDao;

	@Autowired
	private RemoteBaseService remoteService;

	@Override
	public void add(AuScontent sa, Long userId) {

		auScontentDao.add(sa);
		remoteService.addWorkFlow("sharingApplication", UuidUtil.getInstance().getUUid(),
				userId == null ? "0" : String.valueOf(userId), null, String.valueOf(sa.getId()), "共享申请", "", "6", null);

	}

	@Override
	public void del(String ids) {

		String[] idArray = ids.split(",");
		auScontentDao.del(idArray);

	}

	@Override
	public List<Map<String, Object>> getByConditionForPage(String status, List<String> showColumns,
			String[] additionalColumns, String condition, Page page) {

		if (CollectionUtils.isEmpty(showColumns)) {

			throw new ServiceException("至少选择一列");

		}

		List<String> conditions = SQLBuilder.createConditionSql(condition);

		return auScontentDao.selectByConditionForPage(status, showColumns, additionalColumns, conditions, page);
	}

	@Override
	public void update(AuScontent sa) {
		auScontentDao.update(sa);

	}

	@Override
	public AuScontent getAuScontentById(String id) {
		return auScontentDao.select(id);

	}

	@Override
	public boolean getAuScontentByToken(String token) {

		return auScontentDao.selectAuScontentByToken(token) > 0;
	}

	@Override
	public AuScontent getByToken(String token) {

		return auScontentDao.selectByToken(token);
	}

	@Override
	public int getAuScontentDeptNum() {

		return auScontentDao.selectAuScontentDeptNum();
	}

}
